package initialize

import (
	"github.com/spf13/viper"
	"go.uber.org/zap"
)

func GetSystemConfig() bool {
	viper.AutomaticEnv()
	getString := viper.GetString("SHOP_MODE")
	if getString == "prod" {
		return true
	} else if getString == "dev" {
		return false
	}
	return false
}

func Logger() (*zap.Logger, error) {
	cfg := GetSystemConfig()
	if cfg {
		config := zap.NewProductionConfig()
		config.OutputPaths = []string{"/logger.log"}
		return config.Build()
	} else {
		dev, err := zap.NewDevelopment()
		return dev, err
	}
}

func InitLogger() {
	logger, err := Logger()
	if err != nil {
		return
	}
	zap.ReplaceGlobals(logger)
}
